package com.kokomi.handler;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kokomi.pojo.Book;
import com.kokomi.pojo.MyPageData;
import com.kokomi.pojo.Result;
import com.kokomi.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;

public class InitTopSaleRunner implements CommandLineRunner {

    @Autowired
    BookService bookService;
    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public void run(String... args) throws Exception {
        Page<Book> page = new Page<>(1,5);
        bookService.page(page, new QueryWrapper<Book>().orderByDesc("buy_count"));
        MyPageData myPageData = new MyPageData(page.getTotal(), page.getRecords());

        redisTemplate.opsForValue().set("book:list::com.kokomi.controller.Bookcontroller:getTopBooks:1:5:", Result.ok(myPageData,"获取成功"));

    }
}
